<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  
  <body>
  
  </body>
  
  <script>
    /* 同步 */
    {
      function doStep1(init) {
        return init + 1;
      }
      function doStep2(init) {
        return init + 2;
      }
      function doStep3(init) {
        return init + 3;
      }
      
      let result = 0;
      result = doStep1(result);
      result = doStep2(result);
      result = doStep3(result);
      console.log(result);//6
    }
    
    /* 异步 */
    {
      console.log('start');
      
      new Promise(() => {
        setTimeout(() => {
          console.log('wait');
        }, 2000);
      });
      
      console.log('end');
      
      // 输出顺序 start-end-wait
    }
    
    /* 回调 */
    {
      function doStep1(init, callback) {
        const result = init + 1;
        callback(result);
      }
      function doStep2(init, callback) {
        const result = init + 2;
        callback(result);
      }
      function doStep3(init, callback) {
        const result = init + 3;
        callback(result);
      }
      
      doStep1(0, result1 => {
        doStep2(result1, result2 => {
          doStep3(result2, result3 => {
            console.log(result3);//6
          });
        });
      });
    }
  </script>
</html>